import type { IComsUnions } from "@/types";

export interface IUnAllowPrintCom {
  materialName: IComsUnions;
  comName: string;
}

const unAllowPrintComArr: IUnAllowPrintCom[] = [
  { materialName: "option-select", comName: "下拉" },
  { materialName: "rate-score", comName: "评价/打分" },
  { materialName: "date-select", comName: "日期/时间" },
];

/**
 * 判断是否是不可打印的组件
 * @param value 组件名称
 * @returns 不可打印的组件
 */
export function isUnAllowPrintCom(value: IComsUnions) {
  return unAllowPrintComArr.find((item) => item.materialName === value);
}

/**
 * 获取编辑器中所有不能打印的组件
 * @param coms 编辑器组件数组
 * @returns 不能打印的组件数组
 */
export function getUnAllowPrintComs(
  coms: { name: IComsUnions }[],
): IUnAllowPrintCom[] {
  const unAllowPrintComs: IUnAllowPrintCom[] = [];

  coms.forEach((com) => {
    const unAllowPrintCom = unAllowPrintComArr.find(
      (item) => item.materialName === com.name,
    );
    if (unAllowPrintCom) {
      unAllowPrintComs.push(unAllowPrintCom);
    }
  });

  return unAllowPrintComs;
}
